<?php
/**
 *
 * @author: xaboy<365615158@qq.com>
 * @day: 2017/12/28
 */

namespace app\admin\model;


/**
 * TODO 订单修改状态记录Model
 * Class StoreOrderStatus
 * @package app\models\store
 */
class StoreOrderStatus extends BaseModel
{
    /**
     * 模型名称
     * @var string
     */
    protected $name = 'store_order_status';


    public static function status($oid,$change_type,$change_message,$change_time = null,$change_name='')
    {
        if($change_time == null) $change_time = time();
        $ip = request()->ip();
        return self::create(compact('oid','change_type','change_message','change_time','ip','change_name'));
    }

    public static function getTime($oid,$change_type)
    {
        return self::where('oid',$oid)->where('change_type',$change_type)->value('change_time');
    }


    public function getChangeTimeAttr($value){
        return date('Y-m-d',$value);
    }

    public static function setStatus($oid, $type, $message,$name='')
    {
        $data['oid'] = (int)$oid;
        $data['change_type'] = $type;
        $data['change_message'] = $message;
        $data['change_time'] = time();
        $data['ip']   = request()->ip();
        $data['change_name'] = $name;
        self::create($data);
    }

}